package com.jshan.blog.result;

import com.jshan.blog.enums.ResultCodeEnum;
import lombok.Data;

@Data
public class Result<T> {

    // private Boolean success;

    private Integer code;

    private String message;

    private T data;

    public static Result ok() {
        Result result = new Result();
        // result.setSuccess(true);
        result.setCode(ResultCodeEnum.SUCCESS.getCode());
        result.setMessage(ResultCodeEnum.SUCCESS.getDesc());
        return result;
    }

    public static <T> Result ok(T data) {
        Result result = new Result();
        // result.setSuccess(true);
        result.setCode(ResultCodeEnum.SUCCESS.getCode());
        result.setMessage(ResultCodeEnum.SUCCESS.getDesc());
        result.setData(data);
        return result;
    }

    public static <T> Result ok(Integer code, String msg, T data) {
        Result result = new Result();
        // result.setSuccess(true);
        result.setCode(code);
        result.setMessage(msg);
        result.setData(data);
        return result;
    }
    public static <T> Result ok(Integer code, String msg) {
        Result result = new Result();
        // result.setSuccess(true);
        result.setCode(code);
        result.setMessage(msg);
        return result;
    }
    public static <T> Result ok(Integer code,  T data) {
        Result result = new Result();
        // result.setSuccess(true);
        result.setCode(code);
        result.setData(data);
        return result;
    }
    public static <T> Result ok(String msg, T data) {
        Result result = new Result();
        // result.setSuccess(true);
        result.setMessage(msg);
        result.setData(data);
        return result;
    }

    public static Result fail() {
        Result result = new Result();
        // result.setSuccess(false);
        result.setCode(ResultCodeEnum.FAIL.getCode());
        result.setMessage(ResultCodeEnum.FAIL.getDesc());
        return result;
    }

    public static <T> Result fail(T data) {
        Result result = new Result();
        // result.setSuccess(false);
        result.setCode(ResultCodeEnum.FAIL.getCode());
        result.setMessage(ResultCodeEnum.FAIL.getDesc());
        result.setData(data);
        return result;
    }

    public static <T> Result fail(Integer code, String msg, T data) {
        Result result = new Result();
        // result.setSuccess(false);
        result.setCode(code);
        result.setMessage(msg);
        result.setData(data);
        return result;
    }
    public static <T> Result fail(Integer code, String msg) {
        Result result = new Result();
        // result.setSuccess(false);
        result.setCode(code);
        result.setMessage(msg);
        return result;
    }



    public static Result noLogin() {
        Result result = new Result();
        // result.setSuccess(false);
        result.setCode(ResultCodeEnum.NO_LOGIN.getCode());
        result.setMessage(ResultCodeEnum.NO_LOGIN.getDesc());
        return result;
    }

    public static <T> Result noLogin(T data) {
        Result result = new Result();
        // result.setSuccess(false);
        result.setCode(ResultCodeEnum.NO_LOGIN.getCode());
        result.setMessage(ResultCodeEnum.NO_LOGIN.getDesc());
        result.setData(data);
        return result;
    }

}
